﻿using B.S.Base.Write.API.Application.Command;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using WEBAPI.ErroeCode;


namespace B.S.Base.Write.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AddMomentController : ControllerBase
    {
      private readonly  IMediator mediator;
       private readonly ILogger<AddMomentController> logger;
        public AddMomentController(IMediator mediator, ILogger<AddMomentController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
 
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="add">数据</param>
        /// <returns>任务返回</returns>
        [HttpPost]
        public async Task<APIResult<int>> Addaccount(AddAccountCommand add)
        {
            try
            {
                var result = await mediator.Send(add);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="accountId">ID</param>
        /// <returns>任务返回</returns>
        [HttpDelete]
        public async Task<APIResult<object>> Deleteaccount(int AccountId)
        {
            try
            {
                DeleteaccountCommand delete = new DeleteaccountCommand()
                {
                    AccountId = AccountId
                };
                var result = await mediator.Send(delete);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="put">数据</param>
        /// <returns>任务返回</returns>
        [HttpPut]
        public async Task<APIResult<int>> Updateaccount(UpdateAccountCommand put)
        {
            try
            {
                var result = await mediator.Send(put);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
      
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="add">数据</param>
        /// <returns>任务返回</returns>
        [HttpPost]
        public async Task<APIResult<int>> Addrole(AddRoleCommand add)
        {
            try
            {
                var result = await mediator.Send(add);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="RoleId">ID</param>
        /// <returns>任务返回</returns>
        [HttpDelete]
        public async Task<APIResult<int>> Deleterole(int RoleId)
        {
            try
            {
                DeleteRoleCommand delete = new DeleteRoleCommand()
                {
                    RoleId = RoleId
                };
                var result = await mediator.Send(delete);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="put">数据</param>
        /// <returns>任务返回</returns>
        [HttpPut]
        public async Task<APIResult<int>> Updaterole(UpdateRoleCommand put)
        {
            try
            {
                var result = await mediator.Send(put);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 分配人员
        /// </summary>
        /// <param name="add">数据</param>
        /// <returns>任务返回</returns>
        [HttpPost]
        public async Task<APIResult<object>> Addroleaccount(AddRoleaccountCommand add)
        {
            try
            {
                var result = await mediator.Send(add);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除用户角色
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<APIResult<object>> DeleteUserRole([FromQuery] DeleteRoleaccountCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="add">数据</param>
        /// <returns>任务返回</returns>
        [HttpPost]
        public async Task<APIResult<object>> AddMenu(AddMenuCommand add)
        {
            try
            {
                var result = await mediator.Send(add);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="add">数据</param>
        /// <returns>任务返回</returns>
        [HttpPut]
        public async Task<APIResult<object>> UpdateMenu(UpdateMenuCommand add)
        {
            try
            {
                var result = await mediator.Send(add);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="add">数据</param>
        /// <returns>任务返回</returns>
        [HttpDelete]
        public async Task<APIResult<object>> DeleteMenu(int Id)
        {
            try
            {
                DeleteMenuCommand command = new DeleteMenuCommand()
                {
                    Id = Id
                };
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 添加权限
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> CreatePeimission(AddMenutRoleCommand command)
        {
            return mediator.Send(command);
        }
        
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="add">数据</param>
        /// <returns>任务返回</returns>
        [HttpPost]
        public async Task<APIResult<int>> Addapprove(AddApproveCommand add)
        {
            try
            {
                var result = await mediator.Send(add);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 请假审批
        /// </summary>
        /// <param name="put">数据</param>
        /// <returns>任务返回</returns>
        [HttpPut]
        public async Task<APIResult<int>> Updateapprove(UpdateApproveCommand put)
        {
            try
            {
                var result = await mediator.Send(put);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除请假
        /// </summary>
        /// <param name="Id">数据</param>
        /// <returns>任务返回</returns>
        [HttpDelete]
        public async Task<APIResult<int>> DeleteApprove(int Id)
        {
            try
            {
                DeleteApproveCommand command = new DeleteApproveCommand()
                {
                    Id = Id
                };
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdateStatu([FromBody] UpdateStatuCommand command)
        {
            try
            {
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("异常处理" + ex.Message);
                throw;
            }
        }
    }

}
